home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / interp / tclStruct1.2.tar.gz / tclStruct1.2.tar / tclStruct1.2 / tclStruct.h < prev    next >
C/C++ Source or Header  |  1995-09-12  |  6KB  |  160 lines

  1. /*
  2.  *    tclStruct package
  3.  *  Support 'C' structures in Tcl
  4.  *
  5.  *  Written by Matthew Costello
  6.  *  (c) 1995 AT&T Global Information Solutions, Dayton Ohio USA
  7.  *
  8.  *  See the file "license.terms" for information on usage and
  9.  *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  */
  12. #ifndef STRUCT_VERSION
  13.  
  14. #ifndef lint
  15. static char struct_headerID[] = "@(#)tclStruct:tclStruct.h    1.9    95/09/12";
  16. #endif
  17.  
  18.  
  19. #define STRUCT_VERSION        "1.2"
  20. #define STRUCT_MAJOR_VERSION    1
  21. #define STRUCT_MINOR_VERSION    2
  22.  
  23. /*
  24.  *  Our 'object's (or structures) are all known by the following
  25.  *  Struct_Object.
  26.  */
  27. typedef struct Struct_Object {
  28. #ifdef STRUCT_MAGIC
  29.     unsigned int    magic;  /* magic number */
  30. #endif
  31.     void *        data;    /* actual data */
  32.     unsigned int    size;    /* data size (used for read/write & control) */
  33.     struct Struct_TypeDef *type;    /* type of object */
  34. } Struct_Object;
  35.  
  36.  
  37. /*
  38.  *  This structure is used to hold a type defintion.
  39.  *  Named type definitions (typedef's) are
  40.  *  stored in a Tcl hash table, with one typedef hash
  41.  *  table per interpreter.
  42.  */
  43. typedef struct Struct_TypeDef {
  44. #ifdef STRUCT_MAGIC
  45.     unsigned int    magic;  /* magic number */
  46. #endif
  47.     char *        name;        /* name of type (for debug) */
  48.     int        refcount;    /* reference count */
  49.     int        size;        /* the size of the type */
  50.     int        align;        /* alignment restrictions */
  51.     int        flags;
  52.     char *        fill;        /* fill character or int */
  53.     union {
  54.      struct {    /*STRUCT_FLAG_IS_ARRAY*/
  55.         struct Struct_TypeDef *array_elem;    /* type of array element */
  56.         char *        fill;        /* fill character or int */
  57.      } a;    /* Array */
  58.      struct {    /*STRUCT_FLAG_IS_STRUCT*/
  59.         struct Struct_StructElem *struct_def;
  60.         int        num_elements;    /* number of structure elements */
  61.      } s;    /* Struct */
  62.      struct {    /*STRUCT_FLAG_IS_POINTER*/
  63.         struct Struct_TypeDef *array_elem;    /* typedef of array element */
  64.      } p;    /* Pointer */
  65.      struct {    /*STRUCT_FLAG_NONE*/
  66.         int dummy;
  67.      } b;    /* Builtin type (handled by TraceProc) */
  68.     } u;
  69.     Tcl_VarTraceProc *TraceProc; /* tcl trace proc to be called for reading/writing this type */
  70. } Struct_TypeDef;
  71.  
  72. #define STRUCT_FLAG_NONE    0
  73. #define    STRUCT_FLAG_IS_BUILTIN    0x0000    /* default type is "builtin" */
  74. #define STRUCT_FLAG_IS_ARRAY    0x0001
  75. #define STRUCT_FLAG_IS_STRUCT    0x0002
  76. #define STRUCT_FLAG_IS_POINTER    0x0004
  77. #define STRUCT_FLAG_IS_ADDR    0x0008    /* special for _addr_ only! */
  78. #define STRUCT_FLAG_IS_MASK    0x000f    /* kind of types (at 'C' level) */
  79.  
  80.     /* Passed to Struct_NewType */
  81. #define STRUCT_FLAG_ALIGN_SIZE    0x00000100    /* align element to size */
  82. #define STRUCT_FLAG_TRACE_ARRAY    0x00000200    /* trace works on arrays */
  83. #define STRUCT_FLAG_TRACE_BASIC    0x00000400    /* indivisible trace function */
  84.     /* Used internally */
  85. #define STRUCT_FLAG_RECURSIVE    0x00000800    /* recurse definition */
  86.  
  87.     /* What features of a type may be set */
  88. #define STRUCT_FLAG_USE_FILL    0x00001000    /* Fill string may be set */
  89. #define STRUCT_FLAG_USE_STRICT    0x00002000    /* Uses STRICT flag */
  90. #define STRUCT_FLAG_USE_NULLOK    0x00004000    /* Uses NULL_OK flag */
  91. #define STRUCT_FLAG_USE_SIGN    0x00008000
  92. /* #define STRUCT_FLAG_USE_JUST    0x00010000    */
  93. #define STRUCT_FLAG_USE_ENDIAN    0x00040000    /* Type cares about Endian */
  94.  
  95. #define STRUCT_FLAG_BUILTIN    0x00100000
  96. #define STRUCT_FLAG_STRICT    0x00200000    /* perform strict checking */
  97. #define STRUCT_FLAG_NULL_OK    0x00400000    /* NULL values are okay */
  98. #define STRUCT_FLAG_UNSIGNED    0x00800000    /* number is unsigned */
  99. #define STRUCT_FLAG_BIG_ENDIAN    0x04000000    /* Type is BIG endian */
  100. #define STRUCT_FLAG_VARLEN    0x08000000    /* variable length type */
  101.  
  102. #define STRUCT_FLAG_JUST_NONE   0x00000000
  103. #define STRUCT_FLAG_JUST_LEFT   0x01000000
  104. #define STRUCT_FLAG_JUST_RIGHT  0x02000000
  105. #define STRUCT_FLAG_JUST_CENTER 0x03000000
  106. #define STRUCT_FLAG_JUST_MASK    0x03000000
  107.  
  108. /*  For structures, each element of a structure is defined
  109.  *  by this array.
  110.  */
  111. typedef struct Struct_StructElem {
  112.     char *            name;
  113.     Struct_TypeDef        *type;
  114.     int            offset;
  115. } Struct_StructElem;
  116.  
  117.  
  118. #ifdef STRUCT_MAGIC
  119. #define STRUCT_MAGIC_OBJECT    ((unsigned int)0xfe0781ff)
  120. #define STRUCT_MAGIC_TYPE    ((unsigned int)0xfe0782ff)
  121. #endif
  122.  
  123.  
  124. /*
  125.  *  Exported tclStruct procedures:
  126.  */
  127.  
  128. EXTERN CONST char *    Struct_AccessElement _ANSI_ARGS_((Tcl_Interp *,
  129.                 Struct_Object *,char*));
  130. EXTERN void        Struct_AttachType _ANSI_ARGS_((Struct_TypeDef *));
  131. EXTERN    Struct_TypeDef *    Struct_CloneType _ANSI_ARGS_((ClientData,
  132.                 Tcl_Interp *, const char *, Struct_TypeDef *));
  133. EXTERN Struct_TypeDef *    Struct_DefArray _ANSI_ARGS_((ClientData,
  134.                 Tcl_Interp *, Struct_TypeDef *, int));
  135. EXTERN int        Struct_DefType _ANSI_ARGS_((ClientData,
  136.                 Tcl_Interp *, CONST char *,char *));
  137. EXTERN void        Struct_DeleteObject _ANSI_ARGS_((Struct_Object *));
  138. EXTERN CONST char *    Struct_GenerateName _ANSI_ARGS_((const char *));
  139. EXTERN ClientData    Struct_GetClientData _ANSI_ARGS_((Tcl_Interp *));
  140. EXTERN int        Struct_GetObject _ANSI_ARGS_((Tcl_Interp *,
  141.                 const char*,Struct_Object *));
  142. EXTERN int        Struct_GetObjectAndCheck _ANSI_ARGS_((Tcl_Interp *,
  143.                 const char*,const char *,Struct_Object *));
  144. EXTERN int        Struct_Init _ANSI_ARGS_((Tcl_Interp *));
  145. EXTERN Struct_TypeDef *    Struct_LookupType _ANSI_ARGS_((ClientData,
  146.                 Tcl_Interp *,const char *typename));
  147. EXTERN Struct_TypeDef *    Struct_NewType _ANSI_ARGS_((ClientData,
  148.                 Tcl_Interp *, const char *, int, int,
  149.                 Tcl_VarTraceProc *));
  150. EXTERN Struct_Object *    Struct_NewObject _ANSI_ARGS_((Struct_TypeDef *,
  151.                 void *,int));
  152. EXTERN int        Struct_RegisterBuiltInType _ANSI_ARGS_((ClientData, 
  153.                 Tcl_Interp *, const char *, int, int, 
  154.                 Tcl_VarTraceProc *));
  155. EXTERN int        Struct_RegisterType _ANSI_ARGS_((ClientData, 
  156.                 Tcl_Interp *, const char *, Struct_TypeDef *));
  157. EXTERN void        Struct_ReleaseType _ANSI_ARGS_((Struct_TypeDef *));
  158.  
  159. #endif /*STRUCT_VERSION*/
  160.